package com.heima.admin.service.impl;

import com.aliyuncs.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.admin.entity.AdChannel;
import com.heima.admin.mapper.AdChannelMapper;
import com.heima.admin.service.AdChannelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.dtos.PageResult;
import com.heima.model.admin.dtos.ChannelPageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 频道信息表 服务实现类
 * </p>
 *
 * @author HM
 * @since 2023-05-25
 */
@Service
public class AdChannelServiceImpl extends ServiceImpl<AdChannelMapper, AdChannel> implements AdChannelService {
    /**
     * 分页查询
     * */

    @Override
    public PageResult<AdChannel> pageQuery(ChannelPageDTO dto) {
        // 设置分页参数
        IPage<AdChannel> page = new Page<>(dto.getPage(), dto.getSize());
        // 设置查询条件
        LambdaQueryWrapper<AdChannel> queryQrapper = new LambdaQueryWrapper<>();
        queryQrapper.like(StringUtils.isNotEmpty(dto.getName()), AdChannel::getName, dto.getName());
        // 分页查询
        IPage<AdChannel> pageResponse = this.page(page, queryQrapper);
        // 组装结果
        return new PageResult<>(dto.getPage(), dto.getSize(),
                pageResponse.getTotal(), pageResponse.getRecords());
    }
}
